{% extends "base.html" %}
{% block title %}{% endblock %}
{% block style %}{% endblock %}
{% block body1 %}{% include "nav.html" %} {% endblock %}
{% block bodyside %}{% endblock %}
{% block bodymain %}
    <table class="table table-bordered table-condensed">
        <tr><th>卡类</th><th>测试</th><th>周卡</th><th>月卡</th><th>永久</th></tr>
        <tr><th>配额</th><th>{{testcard}}</th><th>{{weekcard}}</th><th>{{monthcard}}</th><th>{{foevercard}}</th></tr>
    </table>
    <h2>温馨提示：注册卡版本和软件版本严格对应，否则无法正常注册，请谨慎选择！</h2>
    <div class="tabbable" id="tabs-916498">
				<ul class="nav nav-tabs">
					<li class="active">
						 <a href="#panel-815220" data-toggle="tab">注册码创建</a>
					</li>
					<li>
						 <a href="#panel-412598" data-toggle="tab">注册码管理</a>
					</li>
					<li>
						 <a href="#panel-412599" data-toggle="tab">配额转让</a>
					</li>
				</ul>

				<div class="tab-content">
					<div class="tab-pane" id="panel-412598">

                        <div class="panel-group" id="panel-544492">
                        <div class="panel panel-default">
                                    <div class="panel-heading">
                                         <a class="panel-title collapsed" data-toggle="collapse" data-parent="#panel-544491" href="#panel-element-330644">注册码解绑</a>
                                    </div>
                                    <div id="panel-element-330644" class="panel-collapse collapse">
                                        <div class="panel-body">
                                                <label>注册码：</label>
                                            <input id="canceltoken" type="text" class="input-block-level" >
                                            <button class="btn-gray" onclick="canel()" type="submit">解绑</button><br>
                                        </div>
                                    </div>
                                </div>
                        <div class="panel panel-default">
                                    <div class="panel-heading">
                                         <a class="panel-title collapsed" data-toggle="collapse" data-parent="#panel-544491" href="#panel-element-330645">注册码续费</a>
                                    </div>
                                    <div id="panel-element-330645" class="panel-collapse collapse">
                                        <div class="panel-body">
                                                <label>注册码：</label>
                                            <input id="addtimetoken" type="text" class="input-block-level" ><br>
                                                <label>续费类型：</label>
                                                        <select id="addtimetype" name="type">
                                                  <option value="1">试用</option>
                                                  <option value="7">周卡</option>
                                                  <option value="30">月卡</option>
                                                  <option value="999">永久</option>
                                                </select>
                                            <button class="btn-gray" onclick="addtime()" type="submit">续费</button><br>
                                        </div>
                                    </div>
                                </div>
			        </div>

						 <div class="ibox-content">

                        <nav aria-label="...">
                            <ul class="pager">
                                <li class="previous"><a href="#"><span aria-hidden="true">&larr;</span> 上一页</a></li>

                    每页显示 <select id="len" onchange=func()>
  <option value="10">10</option>
  <option value="20">20</option>
  <option value="50">50</option>
  <option value="100">100</option>
</select>条,第<span id="tokennowpage">1</span>页,共<span id="tokentotalpage"></span>页
                                <li class="next"><a role="button"  >下一页<span aria-hidden="true">&rarr;</span></a></li>
                            </ul>
                        </nav>
 <table class="table table-condensed table-bordered table-hover"  id="getlist"></table>


                    </div>
					</div>

					<div class="tab-pane active" id="panel-815220">

                        <div class="panel-group" id="panel-544491">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                     <a class="panel-title collapsed" data-toggle="collapse" data-parent="#panel-544491" href="#panel-element-330646">创建单个自定义注册码</a>
                                </div>
                                <div id="panel-element-330646" class="panel-collapse collapse">
                                    <div class="panel-body">
                                        <label>版本：</label>
                                                    <select id="createoneversion"name="version">
                                                    {% for i in versions %}
                                                    <option value="{{i.string}}">{{i.version}}</option>
                                                    {% endfor %}
                                            </select>
                                                <label>类型：</label>
                                                        <select id="createonetype" name="type">
                                                  <option value="1">试用</option>
                                                  <option value="7">周卡</option>
                                                  <option value="30">月卡</option>
                                                  <option value="999">永久</option>
                                                </select>
                                        <br><label>注册码：</label>
                                            <input type="text"id="createonetoken" name="token">

                                                <br><label>备注：</label>
                                                 <input type="text" id="createonename"name="name">
                                            <br><label>成交金额：</label>
                                        <input type="text" id="createonemoney" name="money">
                                               <br><button class="btn-gray" onclick="createone()" type="submit">创建固定注册码</button>
                                    </div>
                                </div>
                            </div>
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                     <a class="panel-title collapsed" data-toggle="collapse" data-parent="#panel-544491" href="#panel-element-330647">批量创建随机注册码</a>
                                </div>
                                <div id="panel-element-330647" class="panel-collapse collapse">
                                    <div class="panel-body">
                                       <form action="/json/createmore" method="post">
                                            {% csrf_token %}
                                            <label>版本：</label>
                                                    <select name="version">
                                                    {% for i in versions %}
                                                    <option value="{{i.string}}">{{i.version}}</option>
                                                    {% endfor %}
                                            </select>
                                            <label>类型：</label>
                                                    <select name="type">
                                              <option value="1">试用</option>
                                              <option value="7">周卡</option>
                                              <option value="30">月卡</option>
                                              <option value="999">永久</option>
                                            </select>
                                            <br><label>数量：</label>
                                        <input type="text" name="count">
                                            <br><label>备注：</label>
                                             <input type="text" name="name">
                                            <br><label>成交金额：</label>
                                        <input type="text" name="money">
                                            <br><input type="submit" value="创建随机注册码">
                                        </form>
                                    </div>
                                </div>
                            </div>
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                     <a class="panel-title collapsed" data-toggle="collapse" data-parent="#panel-544491" href="#panel-element-330648">批量创建递增注册码</a>
                                </div>
                                <div id="panel-element-330648" class="panel-collapse collapse">
                                    <div class="panel-body">
                                        <form action="/json/createindex" method="post">
                                            {% csrf_token %}
                                            <label>版本：</label>
                                                    <select name="version">
                                                    {% for i in versions %}
                                                    <option value="{{i.string}}">{{i.version}}</option>
                                                    {% endfor %}
                                            </select>
                                            <label>类型：</label>
                                                    <select name="type">
                                              <option value="1">试用</option>
                                              <option value="7">周卡</option>
                                              <option value="30">月卡</option>
                                              <option value="999">永久</option>
                                            </select>
                                            <br><label>自定义字符：</label>
                                        <input type="text" name="diycode">
                                            <br><label>数量：</label>
                                        <input type="text" name="count">
                                            <br><label>备注：</label>
                                             <input type="text" name="name">
                                            <br><label>成交金额：</label>
                                            <input type="text" name="money">
                                            <br><input type="submit" value="创建序列注册码">
                                        </form>
                                    </div>
                                </div>
                            </div>
			        </div>

					</div>

					<div class="tab-pane" id="panel-412599">
                        <br>
						<label>类型：</label>
                <select id="transfertype" name="type">
          <option value="1">试用</option>
          <option value="7">周卡</option>
          <option value="30">月卡</option>
          <option value="999">永久</option>
        </select>
        <label>数量：</label>
    <input type="text"  id="transfercount" name="count">
        <label>目标用户UID：</label>
    <input type="text" id="transferid" name="id">
        <label>成交金额：</label>
    <input type="text" id="transfermoney" name="money">
        <button class="btn-gray" onclick="transfer()" type="submit">转让配额</button><br>
                        <div class="tab-content">

                        <br>
 <table class="table table-condensed table-bordered table-hover"  id="orderlist">

 </table>
					</div>
				</div>
			</div>
    </div>
{% endblock %}
{% block script %}
<script type="text/javascript">
    tokenstrlist=[];
    orderstrlist=[];
    $("#btn").prop({checked:false});
    var flag=false
    function swapCheck(){
     if(flag){
        $(".check").prop({checked:false});
        flag=false;
        }
        else{
        $(".check").prop({checked:true});
        flag=true;
        }
    }
function canel(){
        var token = $('#canceltoken').val();
        var postdata={'token':token}
		$.post("/json/admincancel",postdata,function(data,status){
		    alert(data.message);
        }
        )}
function addtime(){
        var token = $('#addtimetoken').val();
        var type = $('#addtimetype').val();
        var postdata={'token':token,'type':type}
		$.post("/json/addtime",postdata,function(data,status){
		    alert(data.message);
        }
        )}
function createone(){
        var token = $('#createonetoken').val()
        var version = $('#createoneversion').val()
        var type = $('#createonetype').val();
        var name = $('#createonename').val();
        var money = $('#createonemoney').val();
        var postdata={'token':token,'version':version,'type':type,'name':name,'money':money}
		$.post("/json/create",postdata,function(data,status){
		    alert(data.message);
		    ordernextpage(1,2);
        }
        )}
function transfer() {
    var count = $('#transfercount').val()
    var type = $('#transfertype').val();
    var id = $('#transferid').val();
    var money = $('#transfermoney').val();
    if (money == '') {
        alert('请输入总金额！');
    } else {
        var postdata = {'count': count, 'type': type, 'id': id, 'money': money}
        $.post("/json/transfer", postdata, function (data, status) {
                alert(data.message);
                ordernextpage(1,2);
            }
        )
    }
}
function func(){
        var vs = $('#len').val();
        len=vs;
		var start= 1;
        var num={{listindex.0.0}}
        var totalpage=parseInt(num/vs)+1;
        $('#tokentotalpage').html(totalpage);
        $('#tokennowpage').html(1);
        tokennextpage(start,vs);
}
function tokennextpage(start, len){
        var blog={'start':start,'len':len};
		$.post("/json/topnews",blog,function(data,status){
		            data=data.list;
                    str='<tr><th>NO.</th><th>项目</th><th>注册码</th><th>设备码</th><th>创建时间</th><th>有效期</th><th>类型</th><th><input id="btn" type="checkbox" onclick="swapCheck()"></th></tr>';
		            for(var i in data){
					str=str+'<tr>'+'<td>'+start+'</td>';
					for(var j in data[i]){
					str=str+'<td>'+data[i][j]+'</td>';
					}
					start=start+1;
					str=str+'<td><input class="check" type="checkbox" value="'+data[i][0]+'"></td></tr>';
					}
					tokenstrlist.push(str);
					$('#getlist').html(str);
		}
)}
function ordernextpage(start, len){
        var blog={'start':start,'len':len};
		$.post("/json/orders",blog,function(data,status){
		            data=data.list;
                    str='<tr><th>NO.</th><th>创建时间</th><th>接收人</th><th>卡类型</th><th>数量</th><th>金额</th></tr>';
		            for(var i in data){
					str=str+'<tr>'+'<td>'+start+'</td>';
					for(var j in data[i]){
					str=str+'<td>'+data[i][j]+'</td>';
					}
					start=start+1;
					str=str+'</tr>';
					}
					orderstrlist.push(str);
					$('#orderlist').html(str);
		}
)}
$(document).ready(function(){
		var start= 1;
		var len=10;
        var num={{listindex.0.0}}
        var totalpage=parseInt(num/10)+1;
        $('#tokentotalpage').html(totalpage);
        tokennextpage(start,len);
        ordernextpage(start,len);
        $('.next').click(function(){
        var len=parseInt($('#len').val());
        var totalpage=parseInt(num/len)+1;
        $('#tokentotalpage').html(totalpage);
            var pagenum=parseInt($('#tokennowpage').text());
            if (pagenum<totalpage){
            if(tokenstrlist.length>pagenum){
                str=tokenstrlist[pagenum];
                $('#getlist').html(str);
            }
            else {
            var start=pagenum*len+1;
            tokennextpage(start,len);
            }
            $('#tokennowpage').html(pagenum+1);
        }
    });
        $('.previous').click(function(){
            var pagenum=parseInt($('#tokennowpage').text());
            if(tokenstrlist.length>=pagenum){
                str=tokenstrlist[pagenum-2];
                $('#getlist').html(str);
            }
            else {
                var len=parseInt($('#len').val());
                var start=(pagenum-1)*len;
                tokennextpage(start,len);
            }
            if (pagenum>1) {
            $('#tokennowpage').html(pagenum-1);
            }
        })
});
$.ajaxSetup({headers: {"X-CSRFToken": '{{ csrf_token }}'}});
</script>
{% endblock %}
